package com.janj.servier;

import com.janj.bean.Hero;
import com.janj.dao.HeroMapper;
import com.janj.util.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class HeroServiceImpl implements HeroService {
//查看
    @Override
    public List<Hero> selectAll() {

        //1.获取Session对象
        SqlSession session = MyBatisUtils.getSqlSession();

        //2.得到mapper 执行sql
        HeroMapper mapper = session.getMapper(HeroMapper.class);
        List<Hero> array = mapper.selectAll();

        //3.释放资源
        MyBatisUtils.close();

        return array;
    }

    //修改
    @Override
    public Integer updateHeroValue(Hero newHero) {
        SqlSession session = MyBatisUtils.getSqlSession();
        HeroMapper mapper = session.getMapper(HeroMapper.class);
        Integer lineNUmber = mapper.updateHeroValue(newHero);
        MyBatisUtils.close();
        return lineNUmber;
    }

    @Override
    public Integer deleteHeroValue(Hero newHero) {
        SqlSession session = MyBatisUtils.getSqlSession();
        HeroMapper mapper = session.getMapper(HeroMapper.class);
        Integer lineNumber = mapper.deleteHeroValue(newHero);
        MyBatisUtils.close();
        return lineNumber;
    }
}
